<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>登录页面 - timeFlies</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="author" content="yinqi">
    <link href="/static/cms/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/cms/css/materialdesignicons.min.css" rel="stylesheet">
    <link href="/static/cms/css/style.min.css" rel="stylesheet">
    <style>
        .lyear-wrapper {
            position: relative;
            background-image: url(/static/cms/images/login-bg-5.jpg);
            background-size: cover;
        }

        .lyear-login {
            display: flex !important;
            min-height: 100vh;
            align-items: center !important;
            justify-content: center !important;
        }

        .lyear-login:after {
            content: '';
            min-height: inherit;
            font-size: 0;
        }

        .login-center {
            background-color: rgba(0, 0, 0, .75);
            min-width: 29.25rem;
            padding: 2.14286em 3.57143em;
            border-radius: 3px;
            margin: 2.85714em;
        }

        .login-header {
            margin-bottom: 1.5rem !important;
        }

        .login-header img {
            max-width: 140px;
        }

        .login-center .has-feedback.feedback-left .form-control {
            padding-left: 38px;
            padding-right: 12px;
            background-color: rgba(255, 255, 255, .075);
            border-color: rgba(255, 255, 255, .075)
        }

        .login-center .has-feedback.feedback-left .form-control-feedback {
            left: 0;
            right: auto;
            width: 38px;
            height: 38px;
            line-height: 38px;
            z-index: 4;
            color: #dcdcdc;
        }

        .login-center .has-feedback.feedback-left.row .form-control-feedback {
            left: 15px;
        }

        .login-center .form-control::-webkit-input-placeholder {
            color: rgba(255, 255, 255, .8);
        }

        .login-center .form-control:-moz-placeholder {
            color: rgba(255, 255, 255, .8);
        }

        .login-center .form-control::-moz-placeholder {
            color: rgba(255, 255, 255, .8);
        }

        .login-center .form-control:-ms-input-placeholder {
            color: rgba(255, 255, 255, .8);
        }

        .login-center .custom-control-label::before {
            background: rgba(0, 0, 0, 0.3);
            border-color: rgba(0, 0, 0, 0.1);
        }

        .login-center .lyear-checkbox span::before {
            border-color: rgba(255, 255, 255, .075)
        }
    </style>
</head>

<body>
<div class="row lyear-wrapper">
    <div class="lyear-login">
        <div class="login-center">
            <div class="login-header text-center">
                <a href="{% url 'front:index' %}"><img alt="light year admin" src="/static/cms/images/logo-sidebar.png"></a>
            </div>
            <form action="#!" method="post" id="login-form">
                <div class="form-group has-feedback feedback-left">
                    <input type="text" placeholder="请输入您的账号" class="form-control" name="account"/>
                    <span class="mdi mdi-account form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group has-feedback feedback-left">
                    <input type="password" placeholder="请输入密码" class="form-control" name="password"/>
                    <span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
                </div>
                <div class="form-group has-feedback feedback-left row">
                    <div class="col-xs-7">
                        <input type="text" name="captcha" class="form-control" placeholder="验证码">
                        <span class="mdi mdi-check-all form-control-feedback" aria-hidden="true"></span>
                    </div>
                    <div class="col-xs-5">
                        <img src="{% url 'auth:img_captcha' %}" data-src="{% url 'auth:img_captcha' %}"
                             class="pull-right" id="captcha" style="cursor: pointer;" title="点击刷新" alt="captcha">
                    </div>
                </div>
                <div class="form-group">
                    <button class="btn btn-block btn-primary" id="login-btn">立即登录
                    </button>
                </div>
            </form>
            <footer class="col-sm-12 text-center text-white">

            </footer>
        </div>
    </div>
</div>
<script type="text/javascript" src="/static/cms/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/cms/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/cms/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/static/cms/js/lightyear.js"></script>
<script type="text/javascript" src="/static/cms/js/jquery.ajax.js"></script>
<script>
    // 切换验证码
    $('#captcha').click(function () {
        $(this).attr('src', $(this).attr('data-src') + '?_=' + (new Date()).getTime())
    })
    $('#login-btn').click(function (e) {
        e.preventDefault()
        lightyear.loading('show')
        var form = $(this).parents('#login-form')
        var account = form.find('input[name=account]').val()
        var password = form.find('input[name=password]').val()
        var img_captcha = form.find('input[name=captcha]').val()
        if (!(account && password && img_captcha)) {
            lightyear.loading('hide')
            lightyear.notify('请完整输入, 别偷懒哦~~', 'danger', 1000)
        } else {
            $ajax.post({
                url: '/auth/login/',
                data: {
                    account: account,
                    password: password,
                    img_captcha: img_captcha,
                },
                success: function (res) {
                    lightyear.loading('hide')
                    if (res.code === 200) {
                        lightyear.notify(res.msg, 'success', 1000)
                        setTimeout(function () {
                            location.replace('/cms/')
                        }, 1000)
                    } else {
                        lightyear.notify(res.msg, 'danger', 1000)
                        $('#captcha').click()
                    }
                    form[0].reset()
                },
                fail: function (err) {
                    lightyear.loading('hide')
                    lightyear.notify("请求错误~~", 'danger', 1000)
                    $('#captcha').click()
                }
            })
        }
    })
</script>
</body>
</html>